package com.lagou.controller;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.lagou.pojo.BlogInfo;
import com.lagou.service.BlogIndexService;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

@Controller
@RequestMapping("blog")
public class BlogIndexController {

    @Autowired
    private BlogIndexService blogIndexService;

    @RequestMapping("/pageList")
    public String pageList(Model model, HttpServletRequest request,
                             HttpServletResponse response,
                             @RequestParam(value="start",defaultValue="0")Integer start,
                             @RequestParam(value="size",defaultValue="2")Integer size){
        PageHelper.startPage(start,size,"id desc");
        PageInfo<BlogInfo> page =  new PageInfo<>(blogIndexService.getBlogInfo());
        model.addAttribute("page",page);
        return "client/index";
    }

}
